package samples.d2.lines 
{
	import adobe.utils.CustomActions;
	import flash.utils.setInterval;
	import samples.BaseSample;
	import shapes.shapes2D.Dot;
	import shapes.shapes2D.Line;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Lines3 extends BaseSample
	{
		
		private var dots:Vector.<Dot>;
		private var line:Vector.<Dot>;
		
		public function Lines3() 
		{
			
			dots = new Vector.<Dot>();
			var i:int = 100;
			while ( i-- )
			{
				dots.push( new Dot( 100 + ( sw - 200 ) * Math.random(), 100 + ( sh - 200 ) * Math.random() ) );
			}
			interval = setInterval( update, 1000 );
			update();
		}
		
		private function update():void
		{
			graphics.clear();
			graphics.lineStyle( 0, color );
			for each( var d:Dot in dots )
			{
				d.draw( graphics );
			}
			
			line = new Vector.<Dot>();
			var i:int = 12, r0:int;
			
			while ( i-- )
			{
				r0 = int( Math.random() * dots.length );
				line.push( dots[ r0 ] );
			}
			
			graphics.moveTo( line[ 0 ].x, line[ 0 ].y );
			for ( i = 0; i < line.length; i += 2 )
			{
				graphics.curveTo( line[ i + 1 ].x, line[ i + 1 ].x, line[ i ].x, line[ i ].y );
			}
			
		}
		
	}

}